<& /Elements/Header, Title => $title &>
<& /AssetTracker/Elements/Tabs, Title => $title &>
% if ( $Output =~ /(jpeg|png)/ ) {
<img src="Elements/Graph?<%$param|n%>" />
%#<img src="Elements/Graph?Query=<%$Query|n%><%$param|n%>" />
% }
% elsif ( $Output =~ /(gif)/ ) {
<img border=0 src="Elements/Graph?<%$param|n%>" usemap="#mainmap"/>
%#<img src="Elements/Graph?Query=<%$Query|n%><%$param|n%>" usemap="#mainmap"/>
<MAP Name="mainmap">
<& /AssetTracker/Search/Elements/Graph, %ARGS, Output => 'cmap' &>
</MAP>
% }
% elsif ( $Output =~ /(svg)/ ) {
<embed src="Elements/Graph?<%$param|n%>" type="image/svg+xml" width="800" height="600"/>
%#<embed src="Elements/Graph?Query=<%$Query|n%><%$param|n%>" type="image/svg+xml" width="800" height="600"/>
% } else {
<% %ARGS %><br>
<% $param %><br>
<&   /AssetTracker/Search/Elements/Graph, %ARGS &>
% }
<hr>
Query: <% $Query %>
<br>
<a href="/AssetTracker/Search/Graph.html?<%$param|n%>">link to this graph</a>
<form method="post" action="Graph.html" name="FormatGraph">
<INPUT TYPE=HIDDEN NAME="Query" VALUE="<% $Query %>">

<table>
<tr>
<td valign="bottom">
</td>

<td valign="bottom">
Link Depth:<br>
<INPUT Name="LinkDepth" Value="<%$LinkDepth%>" SIZE=1 MAXLENGTH=1>
<p>
Skip Links:<br>
<SELECT MULTIPLE Name='SkipLinks' SIZE="11">
% foreach my $type ('(show all)', %{RTx::AssetTracker::Asset::LINKMAP()}, 'LocatedAt', 'AtThisLocation' ) {
<option 
% if (grep { $type eq $_ } @$SkipLinks) {
SELECTED
% }
value='<%$type%>'> <%$type%>
% }
</SELECT>
</td>

<td valign="bottom">
Skip Asset Types:<br>
<SELECT MULTIPLE NAME ="SkipTypes" SIZE="<%scalar @{$session{'see_in_types'}}%>">
% foreach my $type (@{$session{'see_in_types'}}) {
<OPTION
    VALUE="<%$type->{Name}%>"
    <% ( grep { $_ eq $type->{Name} } @$SkipTypes ) && 'SELECTED'%>
>
<%$type->{'Name'}%>
</OPTION>
% }
</SELECT>
</td>

<td valign="bottom">
Skip Assets Named Below: <INPUT type="checkbox" Name="SkipAssets" <% $SkipAssets && 'CHECKED' %>><br>
% $SkipNames = join("\n", @$SkipNames) if ref $SkipNames;
% $SkipNames =~ s/\r?\n/\n/g;
% my $skip_string = join("\n", grep { /\w/ } split(/\n/, $SkipNames));
<TEXTAREA Name="SkipNames" ROWS="10"><%$skip_string%></TEXTAREA>
</td>

<td valign="bottom">
Skip Statuses:<br>
<SELECT MULTIPLE NAME ="SkipStatus" SIZE="<%scalar @status%>">
%foreach my $status (@status) {
  <OPTION
   <% ($status eq 'production' and @$SkipStatus == 0) && "SELECTED" %>
   <% (grep { $status eq $_ } @$SkipStatus) && "SELECTED" %>
   VALUE="<%$status%>"><%loc($status)%>
  </OPTION>
% }
</SELECT>
</td>

<td valign="bottom">
Graph Direction:<br>
<SELECT NAME ="Direction">
<OPTION <% $Direction eq 'Vertical'   && 'SELECTED' %>VALUE="Vertical">Vertical
<OPTION <% $Direction eq 'Horizontal' && 'SELECTED' %>VALUE="Horizontal">Horizontal
</OPTION>
</SELECT>
<p>
Output Format:<br>
<SELECT NAME ="Output">
<OPTION <% $Output eq 'gif'  && 'SELECTED' %> VALUE="gif">gif
<OPTION <% $Output eq 'png'  && 'SELECTED' %> VALUE="png">png
<OPTION <% $Output eq 'jpeg' && 'SELECTED' %> VALUE="jpeg">jpeg
<OPTION <% $Output eq 'svg'  && 'SELECTED' %> VALUE="svg">svg
<OPTION <% $Output eq 'text' && 'SELECTED' %> VALUE="text">text
%#<OPTION <% $Output eq 'ps'   && 'SELECTED' %> VALUE="ps">ps
</OPTION>
</SELECT>
</td>

</tr>
</table>

<& /Elements/Submit, Label => loc('Graph'), Name => 'Graph'&>
</form>

<%ARGS>
$Query
$LinkDepth  => 1
$SkipLinks  => [ 'RefersTo', 'ReferredToBy', 'LocatedAt', 'AtThisLocation', ]
$SkipStatus => [ 'retired', ]
$SkipTypes  => [  ]
$SkipNames  => [ 'tivoli' ]
$SkipAssets => 0
$Direction  => 'Vertical'
$Output     => 'gif'
</%ARGS>

<%INIT>
my  $title = loc("Graph");

$SkipLinks  = ref($SkipLinks)  ? $SkipLinks  : [ $SkipLinks ];
$SkipTypes  = ref($SkipTypes)  ? $SkipTypes  : [ $SkipTypes ];
$SkipStatus = ref($SkipStatus) ? $SkipStatus : [ $SkipStatus ];

unless ($session{'see_in_types'}) {

    @{$session{'see_in_types'}} = ();
    my $t = RTx::AssetTracker::Types->new($session{'CurrentUser'});
    $t->UnLimit;
    while (my $type=$t->Next) {
        if ($type->CurrentUserHasRight('SeeType')) {
                my $ds = { Name => $type->Name, Description => $type->Description, id => $type->id };
                push (@{$session{'see_in_types'}}, $ds);
        }
    }
}

my $param;
while ( my ($k, $v) = each %ARGS ) {
    if ( $v =~ /\n/ ) {
        $v =~ s/\r?\n/\n/g;
        $v = [ split(/\n/, $v) ];
    }
    for my $val ( ref($v) ? @$v : $v ) {
        $param .= "&$k=$val"
    }
}

if ( $Output =~ '/(ps)/' ) {
    $m->comp('Elements/Graph', %ARGS);
    $m->abort();
}

</%INIT>
<%ONCE>
#my $type = RTx::AssetTracker::Type->new($session{'CurrentUser'});
my @status = RTx::AssetTracker::Type->StatusArray();
</%ONCE>
